package club.emergency.wechat.question_collection.search.consumer.controller;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.utils.JsonConvert;
import club.emergency.wechat.question_collection.search.consumer.service.QuestionCollectionSearchConsumer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.question_collection.search.consumer.controller
 * Date: 2019/2/21
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Api("收集试题搜索接口")
@RestController
@RequestMapping("/question-collection-search")
public class QuestionCollectionSearchController {

    private QuestionCollectionSearchConsumer questionCollectionSearchConsumer;

    public QuestionCollectionSearchController(QuestionCollectionSearchConsumer questionCollectionSearchConsumer) {
        this.questionCollectionSearchConsumer = questionCollectionSearchConsumer;
    }

    @ApiOperation("根据人员id查询该人员所有收藏的试题")
    @ApiImplicitParam(name = "staffId", value = "人员id", dataType = "long", paramType = "query")
    @PostMapping("/flipListByStaffId")
    public ResponseEntity flipListByStaffId(
            @RequestParam("staffId") Long staffId,
            @RequestParam(value = "categoryAlias", required = false) String categoryAlias,
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize
    ) {
        return new JsonConvert<ResponseEntity>().jsonDecode(questionCollectionSearchConsumer.flipListByStaffId(staffId, categoryAlias, pageNo, pageSize), ResponseEntity.class);
    }

    @ApiOperation("根据人员id和试题id检查是否被收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "staffId", value = "人员id", dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "questionId", value = "试题id", dataType = "long", paramType = "query")
    })
    @PostMapping("/checkIsCollection")
    public ResponseEntity checkIsCollection(
            @RequestParam("staffId") Long staffId,
            @RequestParam("questionId") Long questionId
    ) {
        return new JsonConvert<ResponseEntity>().jsonDecode(questionCollectionSearchConsumer.checkIsCollection(staffId, questionId), ResponseEntity.class);
    }
}
